package com.cloudpivot.receivales.ding.basic.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.cloudpivot.receivales.ding.basic.domain.InteractiveCardForCPDTO;
import com.cloudpivot.receivales.ding.basic.domain.ScenegroupForCPDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 中台相关服务 add update....
 */
@Service
public class CPServiceImpl {

    @Value("${myprops.cpurl}")
    private String CPURL;

    @Autowired
    private HttpAPIServiceForDing httpAPIServiceForDing;

    /**
     * 推送新建的群信息 to 业务中台
     */
    public String addScenegroupInfoToCP(ScenegroupForCPDTO dto){
        String path="api/outservice/addScenegroupInfo";
        String url = String.format("%s%s", CPURL, path);
        try {
            String rsp=httpAPIServiceForDing.doPost(url,JSONObject.toJSONString(dto),null);
            return rsp;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 推送新建的群卡片信息 to 业务中台
     */
    public String addInteractiveCardToCP(InteractiveCardForCPDTO dto){
        String path="api/outservice/addInteractiveCard";
        String url = String.format("%s%s", CPURL, path);
        try {
            String rsp=httpAPIServiceForDing.doPost(url,JSONObject.toJSONString(dto),null);
            return rsp;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
